<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/admin/include/init_admin.jsp" %>
<%@ page import="com.welfare.admin.service.*" %>
<%
	HashList codeUseYn	= CommonUtil.getCodeList("use_yn");		//사용여부
	HashList codeOpenYn	= CommonUtil.getCodeList("open_yn");	//공개여부
	HashList code002	= CommonUtil.getCodeList("002");		//사업구분
	HashList code003	= CommonUtil.getCodeList("003");		//서비스유형
	HashList code004	= CommonUtil.getCodeList("004");		//공급주체
	 
	HashList code501	= CommonUtil.getCodeList("501");	//생애주기
	HashList code502	= CommonUtil.getCodeList("502");	//대상특성
	HashList code503	= CommonUtil.getCodeList("503");	//가구유형
	HashList code504	= CommonUtil.getCodeList("504");	//소득구분
	HashList code505	= CommonUtil.getCodeList("505");	//지원형태
	HashList code506	= CommonUtil.getCodeList("506");	//욕구

	HashList code005	= CommonUtil.getCodeList("005");	//교육기간
	HashList code507	= CommonUtil.getCodeList("507");	//교육시간
	HashList code508	= CommonUtil.getCodeList("508");	//요일

	String tabs_code	= StringUtil.nvl(request.getParameter("tabs_code"), "1");
	String service_id	= StringUtil.nvl(request.getParameter("service_id"));

	String job_type		= "".equals(service_id) ? "C" : "U";


	HashMap infos = new HashMap();
	infos.put("service_id",	service_id);


	ServiceDAO dao 		= new ServiceDAO();
	HashList list 		= dao.selectServiceInfo(infos);			
	HashList docuList	= dao.selectServiceDocuList(infos);


%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title><%= SYSTEM_NAME %></title>
	<%@ include file="/admin/include/cssnjs.jsp"  %>
	<script type="text/javascript" src="../../SE2.3.1.O9858/js/HuskyEZCreator.js" charset="utf-8"></script>

	<script type="text/javascript">
	var oEditors = [];
	
	$(document).ready(function() {
		
		cfInitSE("service_info");
		cfInitSE("extra_1");
		cfInitSE("extra_2");
		
		
		$('#start_dt').mask('9999.99.99').datepicker();

		//탭 초기화
		$('#tabs li[code="<%=tabs_code%>"]').removeClass('off').addClass('on');
		$('#tabs-<%=tabs_code%>').removeClass('hidden');

		/* 탭 클릭 */
		$('li', '#tabs').click(function(){
		    $('.on', '#tabs').removeClass('on').addClass('off');
		    $(this).addClass('on');

			$('#tabs-1:not(.hidden),#tabs-2:not(.hidden),#tabs-3:not(.hidden),#tabs-4:not(.hidden)').addClass('hidden');
			$('#tabs-'+$(this).attr('code')).removeClass('hidden');
			$('#tabs_code').val($(this).attr('code'));
		});
		
		$('.docu_name').change(function() {
			$(this).closest('div').find('input[name="list.job_type"]').val('U');
		});
	});


	function fnSave() {
		if (cfCheckRequired(document.saveForm.service_gubn, '사업구분을 선택하세요')
				&& cfCheckRequired(document.saveForm.service_name, '사업명을 입력하세요')
				&& cfCheckRequired(document.saveForm.service_type, '서비스유형을 입력하세요')
				&& cfCheckRequired(document.saveForm.owner_code, '공급주체를 선택하세요')
				&& cfCheckRequired(document.saveForm.dept_name, '담당부서를 입력하세요')
		) {
			if (confirm(MSG_<%=job_type%>)) {
				oEditors.getById["service_info"].exec("UPDATE_CONTENTS_FIELD", []);
				oEditors.getById["extra_1"].exec("UPDATE_CONTENTS_FIELD", []);
				oEditors.getById["extra_2"].exec("UPDATE_CONTENTS_FIELD", []);
				$('#saveForm').attr('action', './serviceSave.do');
				$('#saveForm').submit();
			}
		}
		
	}

	function fnDelete() {
		if (confirm(MSG_D)) {
			$('#job_type').val('D');
			$('#saveForm').attr('action', './serviceSave.do');
			$('#saveForm').submit();
		}
	}
	
	function fnOpenDocu(oThis) {
		var idx = 0;
		$('#docuList').children().each(function() {
			if ($(this).get(0) == $(oThis).closest('div').get(0)) {
				cfOpen('./selectDocument.jsp?idx=' + idx, 'win_sel_docu', 600, 400);
			}
			idx++;
		});
	}
	
	function fnAddDocu() {
		var txt = '<div style="margin-top:4px;">' +
			'<input type="hidden" name="list.job_type" value="C" />' +
			'<input type="hidden" name="list.service_id" value="<%= service_id %>"/>' +
			'<input type="hidden" name="list.docu_seq" value=""/>' +
			'<input type="hidden" name="list.docu_id" value=""/>' +
			'<input type="text" name="list.docu_name" id="list.docu_name" class="w300" />' +
			'<a href="#nohref" onclick="fnOpenDocu(this)"><img src="../images/ico_popup.gif" align="absmiddle"></a>' + 
			//'<a href="#nohref" onclick="fnAddDocu()"><img src="../images/ico_minus.gif" align="absmiddle"></a>'
			'</div>';
		$("#docuList").append(txt);
	}

	function fnDeleteDocu(oThis) {
		$(oThis).closest('div').hide().find('input[name="list.job_type"]').val('D');
	}

	</script>
</head>
<body>
<div id="wrap">
	<div id="page">
		<div id="contents">
			<div class="menu_title">
				<h1>복지자원<%= "C".equals(job_type)?"등록":"상세" %></h1>
				<p>관리자 > 복지자원관리 > <b>복지자원<%= "C".equals(job_type)?"등록":"상세" %></b></p>
			</div>
			<div class="clear line_01"></div>


			<ul id="tabs" class="tab_01 mt15">
			    <li class="off"  code="1"><p>1. 기본정보</p></li>
			    <li class="off"  code="2"><p>2. 검색정보</p></li>
			
			</ul>


			<form name="saveForm" id="saveForm" method="post" action="">
			<input type="hidden" name="job_type" id="job_type" value="<%= job_type %>"/>
			<input type="hidden" name="tabs_code" id="tabs_code" value="<%= tabs_code %>"/>
			<input type="hidden" name="service_id" value="<%= list.get("service_id", 0) %>"/>
				

			<div id="tabs-1" class="mt15 hidden">

				<table cellpadding="0" cellspacing="0" class="table_01 mt5">
				<colgroup>
					<col width="100px"/>
					<col width="400px"/>
					<col width="100px"/>
					<col/>
				</colgroup>
				<tbody>
					<tr>
						<th><p>사업구분*</p></th>
						<td colspan="3" class="brx">
							<%= StringUtil.makeRadio(code002, "service_gubn", list.get("service_gubn", 0)) %>
						</td>
					</tr>
					<tr>
						<th><p>서비스명*</p></th>
						<td colspan="3" class="brx">
							<input type="text" name="service_name" class="wmax" value="<%= list.get("service_name", 0) %>"  />
						</td>
					</tr>
					<tr>
						<th><p>서비스유형*</p></th>
						<td >
							<%= StringUtil.makeRadio(code003, "service_type", list.get("service_type", 0)) %>
						</td>
						<th><p>공급주체*</p></th>
						<td class="brx">
							<select name="owner_code" class="w120">
							<%= StringUtil.makeOption(code004, list.get("owner_code", 0)) %>
						  	</select>
						</td>
					</tr>
					<tr>
						<th><p>담당부서*</p></th>
						<td>
							<input type="text" name="dept_name" class="wmax" value="<%= list.get("dept_name", 0) %>"  />
						</td>
						<th><p>홈페이지</p></th>
						<td class="brx">
							<input type="text" name="homepage" class="wmax" value="<%= list.get("homepage", 0) %>"  />
						</td>
					</tr>
					<tr>
						<th><p>담당자</p></th>
						<td>
							<textarea name="dept_tel" class="w300"><%= list.get("dept_tel", 0) %></textarea>
						</td>
						<th><p>연락처</p></th>
						<td class="brx">
							<textarea name="tel_no" class="w300"><%= list.get("tel_no", 0) %></textarea>
						</td>
					</tr>
					<tr>
						<th><p>주소</p></th>
						<td colspan="3" class="brx">
							<input type="text" name="address" class="wmax" value="<%= list.get("address", 0) %>"  />
						</td>
					</tr>
					<tr>
						<th><p>사업개요</p></th>
						<td colspan="3" class="brx">
							<textarea name="summary" id="summary" style="width:860px; height:80px"><%= list.get("summary", 0) %></textarea>
						</td>
					</tr>
					<tr>
						<th><p>선정기준</p></th>
						<td colspan="3" class="brx">
							<textarea name="selection" id="selection" style="width:860px; height:80px"><%= list.get("selection", 0) %></textarea>
						</td>
					</tr>
					<tr>
						<th><p>서비스내용</p></th>
						<td colspan="3" class="brx">
							<textarea name="service_info" id="service_info" style="width:860px; height:300px"><%= list.get("service_info", 0) %></textarea>
						</td>
					</tr>
					<tr>
						<th><p>금액</p></th>
						<td colspan="3" class="brx">
							<textarea name="price_info" id="price_info" style="width:860px; height:80px"><%= list.get("price_info", 0) %></textarea>
						</td>
					</tr>
					<tr>
						<th><p>구비서류</p></th>
						<td colspan="3" class="brx">
							<textarea name="document" id="document" style="width:860px; height:80px"><%= list.get("document", 0) %></textarea>
						</td>
					</tr>
					<tr>
						<th><p>예비1</p></th>
						<td colspan="3" class="brx">
							<textarea name="extra_1" id="extra_1" style="width:860px; height:80px"><%= list.get("extra_1", 0) %></textarea>
						</td>
					</tr>
					<tr>
						<th><p>예비2</p></th>
						<td colspan="3" class="brx">
							<textarea name="extra_2" id="extra_2" style="width:860px; height:80px"><%= list.get("extra_2", 0) %></textarea>
						</td>
					</tr>
					<tr>
						<th><p>서식</p></th>
						<td colspan="3" class="brx" id="docuList">
					<%	for (int i = 0; i < docuList.size(); i++) { %>
							<div class="mb4">
								<input type="hidden" name="list.job_type" value="X" />
								<input type="hidden" name="list.service_id" value="<%= service_id %>"/>
								<input type="hidden" name="list.docu_seq" value="<%= docuList.get("docu_seq",i) %>"/>
								<input type="hidden" name="list.docu_id" value="<%= docuList.get("docu_id",i) %>"/>
								<input type="text" name="list.docu_name" value="<%= docuList.get("docu_name",i) %>" class="w300 docu_name" /><a href="#nohref" onclick="fnOpenDocu(this)"><img src="../images/ico_popup.gif" align="absmiddle"/></a>
								<a href="#nohref" onclick="fnDeleteDocu(this)"><img src="../images/btn_remove.gif" align="absmiddle"/></a>
					<%		if (!"".equals(docuList.get("file_id",i))) { %>
								<a href="../../common/fileDownload.jsp?file_id=<%= docuList.get("file_id", i) %>&file_name=<%=docuList.getEncode("docu_name",i) %>"><img src="../images/ico_download.gif"/></a>
					<%		} %>		
							</div>
					<%	} %>
							<div>
								<input type="hidden" name="list.job_type" value="C" />
								<input type="hidden" name="list.service_id" value="<%= service_id %>"/>
								<input type="hidden" name="list.docu_seq" value=""/>
								<input type="hidden" name="list.docu_id" value="" />
								<input type="text" name="list.docu_name"  class="w300" /><a href="#nohref" onclick="fnOpenDocu(this)"><img src="../images/ico_popup.gif" align="absmiddle"/></a>
								<a href="#nohref" onclick="fnAddDocu()"><img src="../images/btn_add.gif" align="absmiddle"/></a>
							</div>
						</td>
					</tr>
					<tr>
						<th><p>공개여부</p></th>
						<td>
							<%= StringUtil.makeRadio(codeOpenYn, "open_yn", list.get("open_yn", 0)) %>
						</td>
						<th><p>사용여부</p></th>
						<td class="brx">
							<%= StringUtil.makeRadio(codeUseYn, "use_yn", list.get("use_yn", 0)) %>
						</td>
					</tr>
					<tr>
						<th><p>등록일</p></th>
						<td>
							<%= list.get("reg_date", 0) %> <%= list.get("reg_user", 0) %>
						</td>
						<th><p>최종수정일</p></th>
						<td class="brx">
							<%= list.get("mod_date", 0) %> <%= list.get("mod_user", 0) %>
						</td>
					</tr>
				</tbody>
				</table>

			</div>
			
			<div id="tabs-2" class="mt15 hidden">

				<table cellpadding="0" cellspacing="0" class="table_01 mt5">
				<colgroup>
					<col width="100px"/>
					<col width="360px"/>
					<col width="100px"/>
					<col/>
				</colgroup>
				<tbody>
					<tr>
						<th><p>생애주기</p></th>
						<td colspan="3" class="brx">
							<%= CommonUtil.makeCheckBox(code501, "srch_age", list.get("srch_age", 0)) %>
						</td>
					</tr>
					<tr>
						<th><p>대상특성</p></th>
						<td colspan="3" class="brx">
							<%= CommonUtil.makeCheckBox(code502, "srch_target", list.get("srch_target", 0)) %>
						</td>
					</tr>
					<tr>
						<th><p>가구유형</p></th>
						<td colspan="3" class="brx">
							<%= CommonUtil.makeCheckBox(code503, "srch_family", list.get("srch_family", 0)) %>
						</td>
					</tr>
					<tr>
						<th><p>소득구분</p></th>
						<td colspan="3" class="brx">
							<%= CommonUtil.makeCheckBox(code504, "srch_income", list.get("srch_income", 0)) %>
						</td>
					</tr>
					<tr>
						<th><p>지원형태</p></th>
						<td colspan="3" class="brx">
							<%= CommonUtil.makeCheckBox(code505, "srch_support", list.get("srch_support", 0)) %>
						</td>
					</tr>
					<tr>
						<th><p>욕구</p></th>
						<td colspan="3" class="brx">
							<%= CommonUtil.makeCheckBox(code506, "srch_needs", list.get("srch_needs", 0)) %>
						</td>
					</tr>
				</tbody>
				</table>

				<div id="program">
				<div class="search_result">교육프로그램</div>
				<table cellpadding="0" cellspacing="0" class="table_01 mt5">
				<colgroup>
					<col width="100px"/>
					<col width="360px"/>
					<col width="100px"/>
					<col/>
				</colgroup>
				<tbody>
					<tr>
						<th><p>교육기간</p></th>
						<td colspan="3" class="brx">
							<%= StringUtil.makeRadio(code005, "prg_period", list.get("prg_period", 0)) %>
						</td>
					</tr>
					<tr>
						<th><p>교육시간</p></th>
						<td colspan="3" class="brx">
							<%= CommonUtil.makeCheckBox(code507, "srch_prg_time", list.get("srch_prg_time", 0)) %>
						</td>
					</tr>
					<tr>
						<th><p>요일</p></th>
						<td colspan="3" class="brx">
							<%= CommonUtil.makeCheckBox(code508, "srch_prg_weekday", list.get("srch_prg_weekday", 0)) %>
						</td>
					</tr>
				</tbody>
				</table>
				</div>
				

			</div>
			
			<div class="mt20 mb10 c">
				<a href="./serviceList.jsp"><img src="../images/btn_list.gif"/></a>
		<%	if ("U".equals(job_type)) { %>
				<a href="#nohref" onclick="fnSave()"><img src="../images/btn_update.gif" /></a>
				<a href="#nohref" onclick="fnDelete()"><img src="../images/btn_delete.gif" /></a>
		<%	} else if ("C".equals(job_type)) { %>
				<a href="#nohref" onclick="fnSave()"><img src="../images/btn_register.gif" /></a>
		<%	} %>
			</div>

			</form>
		</div>
	</div>
</div>

</body>
</html>
